home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / windownt / logoff.zip / LOGOFF.C next >
C/C++ Source or Header  |  1993-06-29  |  1KB  |  59 lines

  1. //
  2. // Logoff
  3. // ======
  4. // 
  5. // Programm Logoff.exe
  6. // 
  7. //
  8.  
  9. #include <windows.h>
  10. #include <stdio.h>
  11.  
  12.  
  13. void main(argc,argv)
  14. int argc;
  15. char *argv[];
  16.  
  17. {
  18.  
  19. HANDLE hToken;
  20. TOKEN_PRIVILEGES tkp;
  21. CHAR buffer[80];
  22.  
  23. /* Get the Process Token */
  24. if (!OpenProcessToken(GetCurrentProcess(),
  25.    TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) {
  26.    printf ( buffer, "OpenProcessToken Error #%d", GetLastError ());
  27.    }
  28. /* Get the LUID for shutdown privilege */
  29.  
  30.    LookupPrivilegeValue(NULL, TEXT("SeShutdownPrivilege"),
  31.              &tkp.Privileges[0].Luid);
  32.  
  33.    tkp.PrivilegeCount = 1;  /* one privilege to set    */
  34.    tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
  35.  
  36. /* Get shutdown privilege for this process. */
  37.  
  38.     if (!AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
  39.            (PTOKEN_PRIVILEGES)NULL, 0)) {
  40.     printf ( buffer, "AdjustTokenPrivileges Error #%d", GetLastError ());
  41.     }
  42.  
  43.  
  44. if (argc<2){
  45.   ExitWindowsEx(EWX_LOGOFF,0);
  46.   exit(1);}
  47. if ((argv[1][0]== 102) || (argv[1][0]== 70)){
  48.   ExitWindowsEx(EWX_FORCE,0);
  49.   exit(1);}
  50. printf("Logoff - Utility V. 1.01 \n");
  51. printf("Logoff     - normal Logoff \n");
  52. printf("Logoff f   - FORCED Logoff \n");
  53. printf("This utility may be freely distributed as long as it remains unchanged.\n");
  54. printf("Please forward suggestions to Martin Sieber (100142,2756)\n");;
  55. printf("Dedicated to the Windows NT community\n");
  56.  
  57. }
  58.  
  59.